﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class CameraUtils
{
    /// <summary>
    /// 视口坐标转UI坐标
    /// </summary>
    /// <param name="viewPort"></param>
    /// <param name="uiRootCanvas"></param>
    /// <returns></returns>
    public static Vector3 ViewportToUIWorld(Vector3 viewPort,RectTransform uiRootCanvas = null)
    {
        if (uiRootCanvas == null)
        {
            uiRootCanvas = GameObject.Find("RootCanvas").GetComponent<RectTransform>();
        }
        viewPort.z = 0;


        return new Vector2(uiRootCanvas.rect.width * viewPort.x - uiRootCanvas.rect.width * 0.5f,
            uiRootCanvas.rect.height * viewPort.y - uiRootCanvas.rect.height * 0.5f);
    }
}
